﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.ComponentModel;
using System.Windows;

namespace WpfApplication2.Helpers
{
    public class BindingHelper : INotifyPropertyChanged
    {
        public static void SetBinding(BindingHelper bindingHelper, FrameworkElement target, DependencyProperty dp)
        {
            SetBinding(bindingHelper, target, dp, null);
        }


        public static void SetBinding(BindingHelper bindingHelper, FrameworkElement target, DependencyProperty dp, BindingMode? mode)
        {
            Binding binding = new Binding("Value");
            binding.Source = bindingHelper;
            if (mode.HasValue) binding.Mode = mode.Value;
            target.SetBinding(dp, binding);
        }


        private double value;
        public double Value
        {
            get
            {
                return this.value;
            }
            set
            {
                this.value = value;
                if (this.PropertyChanged != null)
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs("Value"));
                }
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        #endregion
    }

}